﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SMWJamecl.BusinessEntities;
using SMWJamecl.BusinessLogic;
using Microsoft.Practices.Unity;
using SMWJamecl.Repository;



namespace SMWJamecl.WEB.Controllers
{
    public class VehiculosController : Controller
    {

        [Dependency]
        public IVehiculoService VehiculoService { get; set; }
        //
        // GET: /Vehiculos/

        
        IVehiculoService vservice;       
        IMarcaService marcaService;
        IModeloService modeloService;

        public VehiculosController()
        {
            if (vservice == null)
            {
                vservice = new VehiculoService();
            }
            if (marcaService == null)
            {
                marcaService = new MarcaService();
            }
            if (modeloService == null)
            {
                modeloService = new ModeloService();
            }
        }


        public ActionResult Index()
        {
            var lista = VehiculoService.GetVehiculosByCriterio("");
            return View(lista);
        }

        [HttpPost]

        public ActionResult Index(string criterio="")
        {
            var lista = VehiculoService.GetVehiculosByCriterio(criterio);
            return View(lista);
        }
        
        public ActionResult Create()
        {
            var marcas = marcaService.GetAllFromMarcas();
            ViewData["Id_Marca"] = new SelectList(marcas, "Id_Marca", "Desc_Marca");
            
            var modelos = modeloService.GetAllFromModelos();
            ViewData["Id_Modelo"] = new SelectList(modelos, "Id_Modelo", "Desc_Modelo");

            return View();
        }
    }
}
